const api = require('../../utils/api.js');
const app = getApp();

Page({
  data: {
    page: 1,
    list: [],
    limit: 20,
    more: true,
    abnorData: {
      imgSrc: '/common/static/images/abnor-04.png',
      text: '暂无相关数据',
    },
    isShowLoading: false,
  },

  onLoad() {
    this.loadDataList();
  },

  onReachBottom() {
    this.loadDataList();
  },

  loadDataList() {
    let that = this;
    let { list, page, more, limit } = that.data;
    if (more) {
      wx.showLoading({
        title: '加载中...',
      });
      app.ws_micro_shoprequest({
        url: api.default.integral_rank,
        data: {
          page,
          limit,
        },
        success: res => {
          wx.hideLoading();
          if (res.code === 0) {
            let newlist = res.data.list;
            if (newlist.length > 0) {
              page += 1;
              that.setData({
                list: list.concat(newlist),
                page,
              });
            } else {
              that.setData({
                more: false,
              });
            }
          } else {
            wx.showToast({
              title: res.msg || '操作出错',
            });
          }
        },
        complete: () => {
          that.setData({
            isShowLoading: true,
          })
        }
      });
    }
  },
});
